#include "ftcsettings.h"
#include <iostream>

static QString m_rootUrl;//文件服务根地址
static long m_connectTimeout = 5000L;//cURL连接超时时长（毫秒）
static long m_timeout = 300000L;     //cURL总超时时长（毫秒）

void FtcSettings::setRootUrl(const QString& rootUrl)
{
	m_rootUrl = rootUrl;
	if (const QString suffix = "/"; !rootUrl.isEmpty() && !std::equal(suffix.rbegin(), suffix.rend(), rootUrl.rbegin()))
	{
		m_rootUrl = m_rootUrl.append(suffix);
	}
	std::cout << "设置Ftc根地址:" << m_rootUrl.toStdString() << std::endl;
}
long FtcSettings::connectTimeout()
{
	return m_connectTimeout;
}
void FtcSettings::setConnectTimeout(const long timeout)
{
	m_connectTimeout = timeout;
}
long FtcSettings::requestTimeout()
{
	return m_timeout;
}
void FtcSettings::setRequestTimeout(const long timeout)
{
	m_timeout = timeout;
}
QString FtcSettings::pathHeartBeat()
{
	return getHttpUrl("file/heartBeat");
}
QString FtcSettings::pathFileInfo()
{
	return getHttpUrl("file/getFileInfoByFileId");
}
QString FtcSettings::pathUpload()
{
	return getHttpUrl("file/upload");
}
QString FtcSettings::pathReUpload()
{
	return getHttpUrl("file/reUpload");
}
QString FtcSettings::getHttpUrl(QString path)
{
	if (m_rootUrl.isEmpty())
	{
		return path;
	}

	return m_rootUrl + path;
}